package leetcode.day;

import java.util.Arrays;
import java.util.*;
// 1984. 学生分数的最小差值
public class MinimumDifference {
    public static void main(String[] args) {
        int[] data = {9,4,1,7};
     minimumDifference(data, 3);

        System.out.println("=======================");
        System.out.println(-5 + 1/4 + 2*-3 + 5.0);

        // 牛客题
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        Deque<String> stack = new LinkedList<String>();
        List<String> list = Arrays.asList(s.split(" "));
        for (int i = 0; i < list.size(); i++) {
            if ("undo".equals(list.get(i)) && i!=0){
                // 被删的进去
                stack.push(list.get(i-1));
                // 当前的出去
                list.remove(i);
                // 被删的出去
                list.remove(i-1);
                i-=2;
                continue;
            }
            if ("redo".equals(list.get(i))){
                if (!stack.isEmpty()){
                    list.remove(i);
                    list.add(i,stack.poll());

                }
            }
        }
        System.out.println(String.join(" ",list));

    }
    // 排序+滑动窗口
    public  static int minimumDifference(int[] nums, int k) {
        if (k == 1) {
            return 0;
        }
        Arrays.sort(nums);
        int min = Integer.MAX_VALUE;
        int index = k - 1;
        // 保证 i和index 差值始终是k-1，也就是i和index的距离始终是k
        for (int i = 0; index < nums.length; i++) {
            min = Math.min(min, nums[index++] - nums[i]);
        }
        return min;
    }


}
